<?php
/**
 * Created by PhpStorm.
 * User: Jerry
 * Date: 2017/1/13
 * Time: 16:19
 */

namespace YMApi\Controller;


use YMApi\Service\CategoryService;
use YMApi\Service\SeminarService;

/**
 * Class CategoryController
 * @package SDXApi\Controller
 */
class CategoryController extends AppController
{

	/**
	 * Created by Jerry
	 */
	public function get_categories()
	{
        //$data = S('ym_all_category_list');
        if(empty($data)){
            $categoryService = new CategoryService();
            $data = $categoryService->getCategories(1);
            S('ym_all_category_list',$data,12*3600);
        }

		if (empty($data)) {
			returnApiError('分类数据为空');
		}

		$arr = array(
			'category_list' => $data,
		);

		returnApiSuccess($arr);
	}

	/**
	 * Created by Jerry
	 */
	public function get_category_by_id()
	{
		$cat_id = I('post.cat_id', 0, 'int');

        $data = S('category_child_info_by_id_'.$cat_id);

        if(empty($data)){
            $categoryService = new CategoryService();
            $data = $categoryService->getCategoryById($cat_id);
            S('category_child_info_by_id_'.$cat_id,$data,12*3600);
        }

		if (empty($data)) {
			returnApiError('分类数据为空');
		}

		returnApiSuccess($data);
	}
}